package com.tianji.learning.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.tianji.common.exceptions.BizIllegalException;
import com.tianji.learning.domain.po.PointsBoardSeason;
import com.tianji.learning.mapper.PointsBoardSeasonMapper;
import com.tianji.learning.service.IPointsBoardSeasonService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 东哥
 * @since 2024-07-01
 */
@Service
@Slf4j
public class PointsBoardSeasonServiceImpl extends ServiceImpl<PointsBoardSeasonMapper, PointsBoardSeason> implements IPointsBoardSeasonService {

    /**
     * 根据时间查询赛季ID
     *
     * @param time
     * @return
     */
    @Override
    public Integer querySeasonByTime(LocalDateTime time) {
        // begin end  =>  create_time
        // select * from table where create_time >= begin and create_time <= end;

        // time  =>  beginTime endTime
        // select * from table where time>= beginTime and time<= endTime;
        PointsBoardSeason season = lambdaQuery()
                .le(PointsBoardSeason::getBeginTime, time)
                .ge(PointsBoardSeason::getEndTime, time)
                .one();
        if(ObjectUtil.isEmpty(season)){
            log.error("赛季信息不存在！");
            throw new BizIllegalException("赛季信息不存在！");
        }
        return season.getId();
    }
}
